﻿using AdminSystem.Application.Commands.ShopCommands;
using AdminSystem.Domain.Entities;
using AdminSystem.EntityFramworkCore;
using AdminSystem.Repositories.Interfaces;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminSystem.Application.CommandHandlers.ShopCommandHandlers
{
    public class ShopQueryCommandHandler : IRequestHandler<ShopQueryCommand, APIResult<List<Shop>>>
    {
        private readonly IBaseRepositories<Shop> shopBase;
        public ShopQueryCommandHandler(IBaseRepositories<Shop> shopBase)
        {
            this.shopBase = shopBase;
        }
        public Task<APIResult<List<Shop>>> Handle(ShopQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Shop>> result = new APIResult<List<Shop>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();

            var list = shopBase.GetAll().Result.ToList();
            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
